<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">


<head th:replace="~{/admin/media/_fragments:: head(~{::title})}">

    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>bili管理</title>
    <link rel="stylesheet" href="../../../static/css/me.css" >
    <link rel="stylesheet" href="../../../static/semantics-dist/semantic.min.css"  >
    <link rel="icon"  href="/favicon.ico">
    <script src="../../../../static/js/jquery-3.7.1.min.js"  ></script>
    <link rel="stylesheet" href="../../../static/lib/editormd-master/css/editormd.min.css"   >

    <script src="../../../static/lib/editormd-master/editormd.min.js"  > </script>

    <script>
        $(document).ready(function() {
            $('#newblog-container').load('/footer/newblog' );
        });
    </script>




    <script src="../../../static/semantics-dist/semantic.min.js" th:src="@{/semantics-dist/semantic.min.js}" ></script>
    <!--    有时候静态页面比thymeleaf好用 -->
    <style >
        body {
            background-image: url(/images/background2.png);
            background-size: cover;/
            background-position: center;
            background-repeat: no-repeat;
            background-attachment: fixed;
        }
    </style>
</head>
<body>

<!--导航-->
<nav th:replace="~{admin/_fragments :: menu(4)}"  class="ui   attached segment m-padded-tb-mini m-shadow-small" >
    <div class="ui container"  >
        <div class="ui   secondary stackable menu">
            <a href="#" th:href="@{/admin/blogs}">
                <h3 class="ui  teal header item" ><i class="ui clipboard outline icon"></i>博客管理</h3></a>
            <a class="m-item m-mobile-hidden  item"  th:classapend = "${(n == 1) ? 'active' : ''}" th:href="@{/admin/blogs/input}"> <i class="ui  home icon">  </i>发文</a>
            <a class="m-item m-mobile-hidden item"  th:classapend = "${(n == 2) ? 'active' : ''}" th:href="@{/admin/todolist}"> <i class="ui tasks  icon">  </i>TODO</a>
            <a class="m-item m-mobile-hidden item"  th:classapend = "${(n == 3) ? 'active' : ''}" th:href="@{/admin/chart}"><i class="ui chart bar icon">  </i> 图表 </a>
            <a class="m-item m-mobile-hidden item"  th:classapend = "${(n == 5) ? 'active' : ''}" th:href="@{/admin/tags}"><i class="ui compass icon">  </i> 机器人</a>
            <a class="m-item m-mobile-hidden item"  th:classapend = "${(n == 4) ? 'active' : ''}" th:href="@{/admin/tags}"><i class="ui play  icon">  </i> 视频 </a>

            <a class="m-item m-mobile-hidden item"  th:classapend = "${(n == 6) ? 'active' : ''}" th:href="@{/}"><i class="ui pencil icon">  </i>主页展示</a>
            <div class="right m-mobile-hidden menu">
                <!--                    <div class="ui dropdown item">-->
                <!--                        <img class="ui avatar image" src="../../static/images/mio3.jpg" th:src="@{/images/mio3.jpg}">-->
                <!--                        长野原美绪-->
                <!--                        <i class="dropdown icon"></i>-->
                <!--                        <div class="menu">-->
                <!--                            <a href="#" class="item" th:href="@{/admin/user}">管理账号</a>-->
                <!--                            <a href="#" class="item" th:href="@{/admin/logout}">退出登录</a>-->
                <!--                        </div>-->
                <!--                    </div>-->
                <div class="ui dropdown item">
                    <img class="ui avatar image" src="../../static/images/mio3.jpg" th:src="@{${session.user.avatar}}" >

                    <a href="#" class="header" th:text="${session.user.nickname}"> </a>
                    <i class="dropdown icon"></i>
                    <div class="menu">
                        <a href="#" class="item" th:href="@{/admin/user}">管理账号</a>
                        <a href="#" class="item" th:href="@{/admin/logout}">退出登录</a>
                    </div>
                </div>
            </div>
        </div>

    </div>
    <a href="#" class="ui menu toggle m-mobile-show   button">
        展开
        <i class="sidebar  icon m-top-right "></i>
    </a>

</nav>
<div  th:replace="~{admin/_fragments ::bilidiv}"  class="ui attached pointing menu">

    <div class="ui container">
        <div class="right menu">

            <a href="#" th:href="@{/admin/media/bilibiliuser}" class="item"><i class="edit teal icon"></i>用户视频表</a>
            <a class="   teal item"   th:href="@{/admin/media/showlocalbilibili/}"> <i class="ui idea teal icon">  </i>本地构建 </a>

        </div>
    </div>
</div>

<!--中间内容th:action="@{/admin/media/bilibiliuser"-->
<div  class="m-container-small m-padded-tb-big">
    <div class="ui segment">


            <div class=" field">
                <div class="ui left labeled input" style="width: 100%">
                    <label class="ui teal basic label">UPs的uid</label>
                    <input type="text" name="name" placeholder="up主uid list，使用英文逗号间隔,建议直接存在自己的文章 里面备用, "   id="biliuidlist" class="fluid"  >

                </div>
            </div>


            <div class="ui right aligned container">
                <button type="button" class="ui button" onclick="window.history.go(-1)" >返回</button>
                <button class="ui teal   button" id="biliSubmitButton">添加</button>
            </div>


    </div>
</div>
<div  class="m-container-small  ">
    <div  class=" ui container">

        <div class="ui two stackable grid">
            <div class="six wide column">
                <div  class=" ui segment" >
                    输入示例

                    建议直接把字符串存储在里面自己的文章里面。（才不是 不想再来一遍增删改查）
                    <div class="ui   secondary vertical  stackable menu" id="uplist">

                    </div>
                </div>
            </div>
            <div class="ten wide column">
                <div  class=" ui segment" >
                    我的list  <input type="number" class="fluid" style="width:50%" id="bilibilipagenum" placeholder="请输入你需要获得页面数 默认为1" min="1" step="1">
                    <div class="segment" id ="videolist">



                    </div>
                </div>
            </div>
        </div>
    </div>
</div>





<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>

<footer th:replace="~{admin/_fragments ::footer}" class="ui    attached segment m-padded-tb-mini m-shadow-big-up  ">

    <br>
    <br>
    <br>
    <div class="ui center aligned container">
        <div class="ui   divided stackable grid">

            <div class="three wide column">

                <div class="middle aligned">

                    <img src="../../../static/images/mio1.png"
                         class="ui middle aligned round image" alt="" style="width: 150px" th:src="@{/images/mio1.png}">
                </div>


            </div>
            <div class="three wide column ">
                <h4 class ="ui   header" >最新文章</h4>
                <div class="ui red  link list">
                    <div id="newblog-container">
                        <div class="ui   link list" th:fragment="newblogList">
                            <a href="#" th:href="@{/blog/{id}(id=${blog.id})}" target="_blank" class="item black m-text-thin" th:each="blog : ${newblogs}" th:text="${blog.title}">用户故事（User Story）</a>
                            <!--/*-->
                            <!--*/-->
                        </div>
                    </div>
                </div>
            </div>
            <div class="three wide column">
                <h4 class ="ui   header">练习方式</h4>
                <div class="ui black  link list">
                    <a href="#" class="item">yonghuname@github.com</a>
                    <a href="#" class="item">等待填充</a>
                    <a href="#" class="item">等待填充</a>
                </div>
            </div>

            <div class="seven wide column">

                <h4 class ="ui   header">网页介绍</h4>

                <p  class="m-text-thin m-text-spaced m-opacity-mini ">学而不思则罔，思而不学则怠。</p>

            </div>
        </div>

        <!--111111111111111111111111111111-->

        <div class="ui   section divider m-padded-tb-">
        </div> <p class="m-text-thin m-text-spaced m-opacity-mini">All rights reserved  </p>
    </div>
</footer>


<script>
    $(document).ready(function() {
        $('.menu.toggle').click(function() {
            $('.m-item').toggleClass('m-mobile-hidden');
        });
    });
    $('.ui.dropdown')
        .dropdown({
            // you can use any ui transition
            // transition: 'drop',
            on:  'hover'
        })
    $('.menu.toggle').click(function () {
        $('.m-item').toggleClass('m-mobile-hide');
    });

    $('.ui.dropdown').dropdown({
        on : 'hover'
    });

    $('.ui.form').form({
        fields : {
            title : {
                identifier: 'name2',
                rules: [{
                    type : 'empty',
                    prompt: '请输入正确'
                }]
            }
        }
    });
    // var videosdata  = [
    //     {
    //         "user_name": "程序员Aurora",
    //         "bv": "BV13K411w7Gs",
    //         "url": "https://www.bilibili.com/video/BV13K411w7Gs/",
    //         "title": "nginx反向代理实现域名访问项目",
    //         "play": 7459,
    //         "duration": 1160,
    //         "pub_date": "2021-04-03",
    //         "now": "2024-03-16 21:04:44"
    //     },
    //     {
    //         "user_name": "程序员Aurora",
    //         "bv": "BV1SK4y1K7R7",
    //         "url": "https://www.bilibili.com/video/BV1SK4y1K7R7/",
    //         "title": "一个由springboot搭建的简洁而又美观的个人博客系统",
    //         "play": 1715,
    //         "duration": 316,
    //         "pub_date": "2021-03-13",
    //         "now": "2024-03-16 21:04:44"
    //     }
    // ];
    function listVideos(videosData) {
        var videoListElement = document.getElementById("videolist");
        videoListElement.innerHTML = ""; // 清空videoListElement元素

        videosData.forEach(function(video) {

            var listblock = document.createElement("div");
            listblock.className = "ui segment";
            // 创建一个新的列表项元素


            // 创建一个包含视频标题的链接元素
            var linkElement = document.createElement("a");
            linkElement.href = "https://www.bilibili.com/video/" + video.bv + "/";
            linkElement.target = "_blank ";
            linkElement.className = "title";
            linkElement.textContent = video.title;

            var titleWrapper = document.createElement("div");
            titleWrapper.className = "left aligned";
            titleWrapper.appendChild(linkElement);
            listblock.appendChild(titleWrapper);

            var grid = document.createElement('div');
            grid.className = 'ui two column stackable grid';
            var dateColumn = document.createElement('div');
            dateColumn.className = 'four wide column';
            var dateContainer = document.createElement('div');
            dateContainer.className = 'ui middle aligned container';


            var dateElement = document.createElement("a");
            dateElement.className = "date";
            dateElement.textContent = " - " + video.pub_date + "  ";
            dateContainer.appendChild(dateElement);
            dateColumn.appendChild(dateContainer);

            var buttonColumn = document.createElement('div');
            buttonColumn.className = 'twelve wide column';
            var buttonContainer = document.createElement('div');
            buttonContainer.className = 'ui right aligned container';
            var button = document.createElement('button');
            button.className = 'ui basic mini right aligned blue my-paddle-tb-mini localshowbilibili button';


            button.dataset.bv = video.bv;
            button.textContent = "本地构建";

            buttonContainer.appendChild(button);
            buttonColumn.appendChild(buttonContainer);


            grid.appendChild(dateColumn);
            grid.appendChild(buttonColumn);


            // 将标题和按钮的包裹元素添加到列表项中

            listblock.appendChild(grid)
            // 将列表项添加到videoListElement中
            videoListElement.appendChild(listblock);
        });
        document.querySelectorAll('.localshowbilibili').forEach(function(button) {
            button.addEventListener('click', function() {
                // 获取按钮的data-bv属性值
                var bvValue = this.getAttribute('data-bv');

                // 构建跳转链接
                var url = '/admin/media/showlocalbilibili/' + encodeURIComponent(bvValue);

                window.open(url, '_blank');
            });
        });
    }

    // 为所有具有localshowbilibili类的按钮添加点击事件监听器
    function getBilibiliUploaderVideos(uid,page_num) {
        const url = `/admin/media/bilibiliuserget?uid=${encodeURIComponent(uid)}&page_num=${encodeURIComponent(page_num)}`;

        fetch(url)
            .then(response => {
                if (!response.ok) {
                    throw new Error('Network response was not ok');
                }
                return response.json(); // 获取响应文本
            })
            .then(data => {
                alert(data); // 处理响应数据
                listVideos(data);
            })
            .catch(error => {
                console.error('There has been a problem with your fetch operation:', error);
                alert('网络请求失败，可能是网络问题或链接错误。请检查链接并重试。');
            });
    }


    function processInput() {
        // 获取输入框的值
        var inputElement = document.getElementById("biliuidlist");
        var inputValue = inputElement.value;

        // 使用逗号分割字符串，并过滤掉空字符串和非数字项
        var numbersArray = inputValue.split(',').map(function(item) {
            var trimmedItem = item.trim(); // 去除空格
            return isNaN(trimmedItem) ? null : parseInt(trimmedItem, 10); // 尝试转换为数字
        }).filter(function(item) {
            return item !== null; // 过滤掉不能转换为数字的项
        });

        var uplistElement = document.getElementById("uplist");
        numbersArray.forEach(function(number) {
            // 创建一个新的div元素，它将包含a元素
            var divElement = document.createElement("div");
            divElement.className = "ui m-padded-tb-small segment"; // 添加必要的类

            // 创建一个新的a元素，它将包含图标和数字
            var linkElement = document.createElement("a");
            linkElement.className = "m-item m-padded-tb-small biliuplistitem"; // 添加必要的类

            // 创建ui用户图标
            var userIcon = document.createElement("i");
            userIcon.className = "ui user icon"; // 添加用户图标的类
            var textNode = document.createTextNode(number);
            linkElement.appendChild(userIcon);
            linkElement.appendChild(textNode);
            divElement.appendChild(linkElement);
            uplistElement.appendChild(divElement);
            var pagenum = document.getElementById("bilibilipagenum").value;
            if(pagenum ==="")  pagenum = 1;
            linkElement.addEventListener('click', function() {
                alert('正在获取当前uid的视频：'+this.textContent+'页面数'+pagenum);

                getBilibiliUploaderVideos(this.textContent,pagenum.toString())
            });
        });
        return false; // 阻止表单提交

    }



    // 获取提交按钮并绑定点击事件
    var submitButton = document.getElementById("biliSubmitButton");
    submitButton.addEventListener('click', processInput);


</script>
</body>
</html>